package com.spic.business.plan.emergencycode.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.spic.business.plan.emergencycode.domain.EmergencyCode;
import com.spic.business.plan.emergencycode.service.IEmergencyCodeService;
import com.spic.business.plan.emergencycode.service.impl.EmergencyCodeServiceImpl;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 应急物资编码Controller
 *
 * @author qishaoping
 * @date 2021-10-28
 */
@RestController
@RequestMapping("/emergencycode")
public class EmergencyCodeController extends BaseController
{
    @Autowired
    private IEmergencyCodeService emergencyCodeService;
    @Autowired
    private EmergencyCodeServiceImpl emergencyCodeServiceImpl;
    @GetMapping("/lists")
     public String selectList(){
        String a = emergencyCodeServiceImpl.getCodeName();
         return a;
     }
    /**
     * 查询应急物资编码列表
     */
    @PreAuthorize(hasPermi = "business/plan:emergencycode:list")
    @GetMapping("/list")
    public TableDataInfo list(EmergencyCode emergencyCode)
    {
        startPage();
        List<EmergencyCode> list = emergencyCodeService.selectEmergencyCodeList(emergencyCode);
        return getDataTable(list);
    }

    /**
     * 导出应急物资编码列表
     */
    @PreAuthorize(hasPermi = "business/plan:emergencycode:export")
    @Log(title = "应急物资编码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmergencyCode emergencyCode) throws IOException
    {
        List<EmergencyCode> list = emergencyCodeService.selectEmergencyCodeList(emergencyCode);
        ExcelUtil<EmergencyCode> util = new ExcelUtil<EmergencyCode>(EmergencyCode.class);
        util.exportExcel(response, list, "应急物资编码数据");
    }

    /**
     * 获取应急物资编码详细信息
     */
    @PreAuthorize(hasPermi = "business/plan:emergencycode:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(emergencyCodeService.selectEmergencyCodeById(id));
    }

    /**
     * 新增应急物资编码
     */
    @PreAuthorize(hasPermi = "business/plan:emergencycode:add")
    @Log(title = "应急物资编码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyCode emergencyCode)
    {
        return toAjax(emergencyCodeService.insertEmergencyCode(emergencyCode));
    }

    /**
     * 修改应急物资编码
     */
    @PreAuthorize(hasPermi = "business/plan:emergencycode:edit")
    @Log(title = "应急物资编码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyCode emergencyCode)
    {
        return toAjax(emergencyCodeService.updateEmergencyCode(emergencyCode));
    }

    /**
     * 删除应急物资编码
     */
    @PreAuthorize(hasPermi = "business/plan:emergencycode:remove")
    @Log(title = "应急物资编码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emergencyCodeService.deleteEmergencyCodeByIds(ids));
    }
}
